# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3 5.4"
pkgname=lua-posixtz
pkgver=0.5
pkgrel=4
pkgdesc="Lua module to extract POSIX timezone from tzdata"
url="http://git.alpinelinux.org/cgit/posixtz.git/"
arch="all"
license="GPL-2.0-only"
for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-posixtz:split_${_i/./_}"
done
source="https://dev.alpinelinux.org/archive/posixtz/posixtz-$pkgver.tar.xz"

builddir="$srcdir"/posixtz-$pkgver
options="!check"

prepare() {
	default_prepare
	for _i in $_luaversions; do
		cp -r "$builddir" "$srcdir"/build-$_i
	done
}

build() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		make LUAPC="lua$_i" core.so
	done
}

package() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		install -D core.so "$pkgdir"/usr/lib/lua/$_i/posixtz/core.so
		install -D posixtz.lua "$pkgdir"/usr/share/lua/$_i/posixtz.lua
	done
}

_split() {
	local d= _ver=$1
	pkgdesc="Lua $_ver module to extract POSIX timezone from tzdata"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}

for _i in $_luaversions; do
	eval "split_${_i/./_}() { _split $_i; }"
done

sha512sums="68dbaab9f4aef166ac2f2d40b49366527b840bebe17a47599fe38345835e4adb8a767910745ece9c384b57af815a871243c3e261a29f41d71f8054df3061b3fd  posixtz-0.5.tar.xz"
